package com.dididoctor.patient.Activity.Capture;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dididoctor.patient.Activity.Doctor.Doctordetail.DoctorDetailActivity;
import com.dididoctor.patient.Activity.Usercentre.Collect.UserCollectActivity;
import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Utils.SharedPreferencesUtils;
import com.dididoctor.patient.Utils.Util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by liying on 2016/4/30.
 */
public class ScanResultsActivity extends EduActivity {
    private String keyWord = "";
    private String name = null;
    private ImageView mIvHead;
    private TextView mTvTop, mTvBottom;
    private Button mBtnSign, mBtnCollection, mBtnRetrun;

    @Override
    public void init() {
        initView();
    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.btn_sign:
                String longitude = SharedPreferencesUtils.getParam(ScanResultsActivity.this, "longitude", "0");
                String latitude = SharedPreferencesUtils.getParam(ScanResultsActivity.this, "latitude", "0");
                Intent intent = new Intent(ScanResultsActivity.this, DoctorDetailActivity.class);
                intent.putExtra("hospitalId", getIntent().getStringExtra("hospitalId"));
                intent.putExtra("longitude", longitude);
                intent.putExtra("latitude", latitude);
                startActivity(intent);
                break;
            case R.id.btn_collection:
                Intent intent1 = new Intent(ScanResultsActivity.this, UserCollectActivity.class);

                startActivity(intent1);
                break;
            case R.id.btn_return:
                ScanResultsActivity.this.finish();
                break;
        }
    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_scanresults);
    }

    public void initView() {
        mIvHead = (ImageView) findViewById(R.id.iv_head);
        mTvTop = (TextView) findViewById(R.id.tv_top);
        mTvBottom = (TextView) findViewById(R.id.tv_bottom);
        mBtnSign = (Button) findViewById(R.id.btn_sign);
        mBtnSign.setOnClickListener(this);
        mBtnCollection = (Button) findViewById(R.id.btn_collection);
        mBtnCollection.setOnClickListener(this);
        mBtnRetrun = (Button) findViewById(R.id.btn_return);
        mBtnRetrun.setOnClickListener(this);


        keyWord = getIntent().getStringExtra("keyWord");
        name = getIntent().getStringExtra("name");
        if (!Util.isEmpty(keyWord) && keyWord.equals("succed")) {
            succed();
        } else {
            fail();
        }
    }

    public boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }


    public void fail() {
        ((TextView) findViewById(R.id.tv_title)).setText("扫描失败");
        mBtnSign.setVisibility(View.GONE);
        mBtnCollection.setVisibility(View.GONE);
        mBtnRetrun.setVisibility(View.VISIBLE);
        mTvTop.setText("抱歉扫描失败");
        mTvBottom.setText("您扫描的并不是医生的二维码");
        mIvHead.setBackgroundResource(R.drawable.img_rob_defeated);
    }

    public void succed() {
        ((TextView) findViewById(R.id.tv_title)).setText("扫描成功");
        mBtnSign.setVisibility(View.VISIBLE);
        mBtnCollection.setVisibility(View.VISIBLE);
        mBtnRetrun.setVisibility(View.GONE);
        mTvTop.setText("恭喜您扫描成功");
        mTvBottom.setText("您已成功收藏" + name + "医生，您可以在“我的收藏”中查看详细信息");
        mIvHead.setBackgroundResource(R.drawable.img_no_order);
    }
}
